﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<nelech.Models.CalendarModel.Event>" %>

<%@ Import Namespace="nelech.Views.Shared.Code" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    CreateEvent
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">

    <script src="../../Scripts/tinymce/jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>

    <script language="javascript" type="text/javascript">
       

        tinyMCE.init({

        elements: "poster",
            theme: "advanced",
                mode: "exact",
                language: "he",
                plugins: "",
                theme_advanced_buttons1_add_before: "forecolor,backcolor,copy,paste,fontselect", theme_advanced_toolbar_location: "top",
                theme_advanced_toolbar_align: "left",
                theme_advanced_more_colors: true,
                theme_advanced_styles: "NormalBold 1=firstBold;Normal 2=first;Normal 3=second;", 
            content_css: "/Content/tinymce.css"
        });    
    </script>

    <script language="javascript" type="text/javascript">
        function repopulateDays(days) {
            var dayElement = document.getElementsByName("Day")[0];
            var selected = dayElement[dayElement.selectedIndex].value;
            if (selected > days)
                selected = 1;
            var dayLength = dayElement.length;

            for (var i = 0; i < dayLength; i++) {
                dayElement.remove(dayElement[0]);
            }

            for (i = 1; i <= days; i++) {
                var o = document.createElement("option");
                o.text = i;
                o.value = i;
                if (i == selected) {
                    o.selected = true;
                }
                dayElement.add(o, null);
            }
        }

        function daysInMonth(iMonth, iYear) {
            return 32 - new Date(iYear, iMonth - 1, 32).getDate();
        }

        function ShowMonthDays() {
            var yearElement = document.getElementsByName("Year")[0];
            var monthElement = document.getElementsByName("Month")[0];
            var year = yearElement[yearElement.selectedIndex].value;
            var month = monthElement[monthElement.selectedIndex].value;
            var days = daysInMonth(month, year);
            repopulateDays(days);
        }    
    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        צור אירוע</h2>
    <%= Html.ValidationSummary() %>
    <% using (Html.BeginForm(this.Model == null ? "CreateEvent" : "EditEvent", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" }))
       {
    %>
    <fieldset>
        <input type="hidden" name="id" value="<%= Html.Encode(this.Model == null ? string.Empty : this.Model.id) %>" />
          <p>
            <label>
                כותרת:</label>
            <%= Html.TextBox("Title",  this.Model == null ? string.Empty : this.Model.Title)%>
        </p>
        <p>
            <label>
                שנה</label>
            <%= Html.DropDownList("Year", Utils.CreateYearListItems(this.Model == null ? null : new Nullable<int>(this.Model.Year)), new { onchange = "ShowMonthDays()" })%>
        </p>
        <p>
            <label>
                חודש</label>
            <%= Html.DropDownList("Month", Utils.CreateMonthListItems(this.Model == null ? null : new Nullable<int>(this.Model.Month)), new { onchange = "ShowMonthDays()" })%>
        </p>
        <p>
            <label>
                יום</label>
            <%= Html.DropDownList("Day", Utils.CreateDayListItems(this.Model == null ? null : new Nullable<int>(this.Model.Day)))%>
        </p>
        <p>
            <label>
                שעת התחלה</label>
            <%= Html.DropDownList("StartMinute", Utils.CreateMinuteListItems(this.Model == null ? null : new Nullable<int>(this.Model.StartMinute)))%>
            :
            <%= Html.DropDownList("StartHour", Utils.CreateHourListItems(this.Model == null ? null : new Nullable<int>(this.Model.StartHour)))%>
        </p>
        <p>
            <label>
                שעת סיום</label>
            <%= Html.DropDownList("EndMinute", Utils.CreateMinuteListItems(this.Model == null ? null : new Nullable<int>(this.Model.EndMinute)))%>
            :
            <%= Html.DropDownList("EndHour", Utils.CreateHourListItems(this.Model == null ? null : new Nullable<int>(this.Model.EndHour)))%>
        </p>
        <p>
            <label>
                פרטים ללוח שנה:</label>
            <%= Html.TextArea("Details", this.Model == null ? string.Empty : this.Model.Details, new { cols = "50", rows = "10" })%>
        </p>
        <p>
            <label>
                פוסטר:</label>
            <%= Html.TextArea("MceDoc", new { rows = "25", cols = "50", id = "MceDoc" })%>
        </p>
        <p>
            <label>
                תמונה:</label>
            <input type="file" name="Photo" />
            <%
                if (this.Model != null && !string.IsNullOrEmpty(this.Model.Photo))
                {
                    Response.Write(string.Format("<img src='{0}' />", this.Model.Photo));
                }
            %>
        </p>
        <p>
            <input type="submit" value="צור" />
        </p>
    </fieldset>
    <%
        }
    %>
</asp:Content>
